﻿using QxFramework.Core;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class Label : UIBase,IPointerEnterHandler,IPointerExitHandler
{
    public string Content;
    public float TimeToShowLabel=0.1f;
    int timecnt;
    GameObject label;
    bool enter;
    void Start()
    {
        timecnt = Mathf.CeilToInt(TimeToShowLabel / Time.deltaTime);
        label = UIManager.Instance.Open("Label", 3, "Label_" + this.GetInstanceID()).gameObject;
       
        label.GetComponentInChildren<Text>().text = Content;
        label.SetActive(false);
    }
    int cnt = 0;
    public void OnPointerEnter(PointerEventData eventData)
    {
        enter = true;

    }
    void FixedUpdate()
    {

        if (!enter) return;
        cnt++;
        if (cnt >= timecnt)
        {
            label.GetComponentInChildren<Text>().text = Content;
            label.transform.position = this.transform.position+
                (Vector3)new Vector3(this.transform.GetComponent<RectTransform>().sizeDelta.x/2+label.GetComponent<RectTransform>().sizeDelta.x/2,0,0);
            label.SetActive(true);
        }
    }
  
    public void OnPointerExit(PointerEventData eventData)
    {
        cnt = 0;
        enter = false;
        label.SetActive(false);
    }
    protected override void OnClose()
    {
        base.OnClose();
        UIManager.Instance.Close("Label", label.name);
    }
}
